﻿using FluentNHibernate.Mapping;
using SmallTune.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmallTune.Mappings
{
    public class GenreMap : ClassMap<Genre>
    {
        public GenreMap()
        {
            Id(x => x.id);
            Map(x => x.created);
            Map(x => x.lastChanged);

            ///A Genre belongs to many albums,
            ///and a album can have many genres (think of a compilation)
            HasManyToMany(x => x.listOfAlbums)
                .Inverse()
                .Cascade.All()
                .Table("AlbumsGenres");

            ///A Genre can have many songs, and a song can have
            ///multiple Genres
            HasManyToMany(x => x.listOfSongs)
                .Inverse()
                .Cascade.All()
                .Table("GenresSongs");

            Map(x => x.name);
        }
    }
}
